using System;
using System.Reflection;
using Framework.Library.Core.Utils.Reflection;

namespace Framework.Library.Core.Utils.Miscellaneous
{
    public static class AssemblyUtils
    {
        public static string GetCompleteProductName(Assembly assembly)
        {
            return GetProductName(assembly) + " " + FormatVersion(assembly.GetName().Version);
        }

        public static string GetProductName(Assembly assembly)
        {
            var productAttribute = ReflectionUtils.GetAttribute<AssemblyProductAttribute>(assembly);

            return productAttribute.Product;
        }

        public static string FormatVersion(Version assemblyVersion)
        {
            if (assemblyVersion.Build == 0)
                return assemblyVersion.Major + "." + assemblyVersion.Minor;
            else
                return assemblyVersion.Major + "." + assemblyVersion.Minor + "." + assemblyVersion.Build;
        }

        public static string GetCopyright(Assembly assembly)
        {
            var copyrightAttribute = ReflectionUtils.GetAttribute<AssemblyCopyrightAttribute>(assembly);

            return copyrightAttribute.Copyright;
        }
    }
}